
const {ccclass, property} = cc._decorator;

@ccclass
export default class WalkEffect extends cc.Component {

    @property({
        type: cc.AudioClip
    })
    walkaudio = null;

    walkaudioID;
    // LIFE-CYCLE CALLBACKS:
    onWalkBegin(param1:number,param2:string){
        this.walkaudioID = cc.audioEngine.play(this.walkaudio, false, 1);
        //cc.log('onWalkBegin: param1[%s], param2[%s]', param1, param2);
    };
    
    onWalkCompleted(param1:number,param2:string){
        //cc.log('onWalkCompleted: param1[%s], param2[%s]', param1, param2);
    };    


    onLoad () {
        let animation = this.node.getComponent(cc.Animation);
        let walkanim = animation.getAnimationState("walk");

        function onPlay(event){                        
            //let state = event.detail;             
            //let type = event.type; 
            //cc.log(walkanim.isPlaying);
        }
        function onStop(event){                                 
            if(walkanim.isPlaying)
            {
                //cc.log(this.walkaudioID)
                cc.audioEngine.stop(this.walkaudioID);
            }
        }
        // 注册        
        animation.on('play',onPlay,this);
        animation.on('stop',onStop,this);
        
    }

    //start () {}

    // update (dt) {}
}
